package com.salon.server.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.salon.server.entity.Beautician;
import com.salon.server.entity.BeauticianProject;
import com.salon.server.entity.Project;
import com.baomidou.mybatisplus.extension.service.IService;
import com.salon.server.mapper.BeauticianMapper;
import com.salon.server.mapper.BeauticianProjectMapper;
import com.salon.server.mapper.ProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author Admin
* @description 针对表【project(美容项目表)】的数据库操作Service
* @createDate 2025-08-26 22:55:58
*/
@Service
public class ProjectService extends ServiceImpl<ProjectMapper, Project> {

    @Autowired
    private BeauticianProjectMapper beauticianProjectMapper;

    @Autowired
    private BeauticianMapper beauticianMapper;

    public List<Beautician> beautician(Project project) {
        // 查询项目关联的美容师
        List<BeauticianProject> beauticianProjectList = beauticianProjectMapper.selectList(new LambdaQueryWrapper<BeauticianProject>()
                .eq(BeauticianProject::getProjectId, project.getId())
        );
        // 关联美容师
        List<Integer> beauticianIdList = beauticianProjectList.stream().map(BeauticianProject::getBeauticianId).collect(Collectors.toList());
        // 查询美容师
        return beauticianMapper.selectBatchIds(beauticianIdList);
    }
}
